import { request } from "umi";

/** 获取积分规则信息 */
export async function getRuleInfo() {
  return request<PATIENT.RuleInfo>(`/api/patient/rule/info`);
}

/** 保存积分规则信息 */
export async function saveRuleInfo(data: PATIENT.RuleInfo) {
  return request<PATIENT.LevelInfo>(`/api/patient/rule/info`, {
    method: 'POST',
    data,
    headers: { Action_Id: '900901015' }
  });
}

/** 积分变更申请 */
export async function integralChangeRequest(
  data: Pick<PATIENT.IntegralInfo, 'identity_no' | 'integral' | 'mobile' | 'patient_id' | 'patient_name' | 'submit_explain' | 'address'>,
  actionId: string
) {
  return request(`/api/patient/integral/approval/info`, {
    method: 'POST',
    data,
    headers: { Action_Id: actionId }
  });
}

/** 批量积分变更申请 */
export async function batchIntegralChangeRequest(data: { patient_id_list: string[], integral: number, submit_explain: string }) {
  return request(`/api/patient/integral/approval/batch`, {
    method: 'POST',
    data,
    headers: { Action_Id: '900901007' }
  });
}

/** 获取积分变更申请列表 */
export async function getIntegralList({ current, pageSize, ...params }: Partial<COMMON.PageParams & PATIENT.IntegralInfo>) {
  return request<COMMON.PageResult<PATIENT.IntegralInfo>>(`/api/patient/integral/approval/${current}/limit/${pageSize}`, {
    params,
    headers: { Action_Id: '900901010' }
  });
}

/** 积分变更审批 */
export async function integralChangeApproval(
  { approval_id, approval_status, submit_explain }: { approval_id: string, approval_status: 'N' | 'D', submit_explain: string },
  actionId: string
) {
  return request(`/api/patient/integral/approval/${approval_id}/${approval_status}`, {
    method: 'POST',
    params: { submit_explain },
    headers: { Action_Id: actionId }
  });
}

/** 积分变更审批 */
export async function batchIntegralChangeApproval(
  { approval_ids, approval_status, approval_explain }: { approval_ids: string[], approval_status: 'N' | 'D', approval_explain: string }
) {
  return request(`/api/patient/integral/approval/batch/${approval_status}`, {
    method: 'POST',
    data: { approval_ids, approval_explain },
    headers: { Action_Id: '900901011' }
  });
}


